import singleton from "@/utils/libs/singleton";
import serial from "./serial";

class runSetp2 {
	//总步数
	setp;
	#serial;
	
	constructor() {
		//执行8个步骤
		this.#serial = new serial();
	
		this.init()

		this.#serial.watch = (canId, data) => {
			switch (canId) {
				case 1010:
					this.handleSetp1(data)
					break;
				case 1020:
					this.handleSetp2(data)
					break;
				case 1030:
					this.handleSetp3(data)
					break;
				case 1040:
					this.handleSetp4(data)
					break;
				case 1050:
					this.handleSetp5(data)
					break;
				case 1060:
					this.handleSetp6(data)
					break;
				case 1070:
					this.handleSetp7(data)
					break;
				case 1080:
					this.handleSetp8(data)
					break;
			}
		}

	}

	init() {
		this.setp = 1;
	}

	runder() {
		console.log("SETP1: 执行干燥压力值")
		this.setp = 1;
		this.status(this.setp, "真空期内胆降压", "用时120S 未到干燥压力值报警，4秒内检测一次", 12)
		this.runSetp1();
	}
	

	runSetp1() {
		//发送指令检测
		setTimeout(() => {
			console.log("RESET: 执行干燥压力值")
			this.#serial.send(1010)
		}, 12000)
	}
	handleSetp1(data) {
		this.setp = 2;
		this.status(this.setp, "测漏检测", "用时40S 升压速率>腔体升压速率,报警E3", 4)
		this.runSetp2()
	}


	runSetp2() {
		//发送指令检测
		setTimeout(() => {
			console.log("SETP2: 测漏")
			this.#serial.send(1020)
		}, 4000)
	}

	handleSetp2(data) {
		//执行下一步 步骤+1
		this.setp = 3;
		this.status(this.setp, "常压真空预热", "立即执行未有其他要求", 3)
		this.runSetp3()
	}

	
	runSetp3() {
		setTimeout(() => {
			console.log("SETP3: 执行预热")
			this.#serial.send(1030)
		}, 3000)
	}

	handleSetp3() {
		//执行下一步
		this.setp = 4;
		this.status(this.setp, "内胆降压和蒸发器降压", "用时120S 灭菌舱的压力应低于“真空期内胆降压值 报警E1", 12)
		this.runSetp4()
	}


	runSetp4() {
		setTimeout(_ => {
		console.log("SETP4: 真空期内胆降压和蒸发器降压")
			this.#serial.send(1040)
		}, 12000)
	}
	handleSetp4(data) {
		//执行下一步
		this.setp = 5;
		this.status(this.setp, "灭菌舱的压力值", "灭菌舱的泄漏值应小于“真空期内胆泄漏率设置 报警E3", 9)
		this.runSetp5()
	}


	runSetp5() {
		setTimeout(_ => {
			console.log('SETP5: 灭菌舱的压力值')
			this.#serial.send(1050)
		}, 9000)
	}
	handleSetp5(data) {
		//执行下一步
		this.setp = 6;
		this.status(this.setp, "抽真空", "等离子开启前将内胆压力抽到180Pa", 3)
		this.handleSetp6()
	}


	runSetp6() {
		setTimeout(_ => {
			console.log('SETP6: 抽真空')
			this.#serial.send(1060)
		}, 3000)
	}
	handleSetp6(data) {
		//执行下一步
		this.setp = 7;
		this.status(this.setp, "等离子", "启动等离子", 3)
		this.runSetp7()
	}

	runSetp7() {
		setTimeout(() => {
			console.log('SETP7: 执行等离子')
			this.#serial.send(1070)
		}, 3000)
	} 
	handleSetp7() {
		//执行下一步
		this.setp = 8;
		this.status(this.setp, "关闭等离子", "提前15s关等离子", 3)
		this.runSetp8()
		
	}
	
	runSetp8() {
		setTimeout(() => {
			console.log('SETP8: 关闭等离子')
			this.#serial.send(1080)
		}, 3000)
	} 
	
	handleSetp8() {
		this.success()
	}
	
	success() {

	}

	err(msg, key) {

	}

	status(setp, name) {

	}

}


export default singleton(runSetp2);